package com.yanqu.road.server.cmd.activity.ad;

import com.yanqu.road.entity.enums.eSystemId;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.ad.AdActivityProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.ad.AdActivityModule;
import com.yanqu.road.server.manger.config.SystemOpenMgr;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_AD_WATCH_FINISH_REWARD, desc = "观看完成领取奖励")
public class WatchFinishRewardCmd extends AbstractCommand {
    private int activityId;
    private boolean getUnlockReward;
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        AdActivityProto.WatchFinishRewardReqMsg reqMsg = AdActivityProto.WatchFinishRewardReqMsg.parseFrom(packet.getBytes());
        activityId = reqMsg.getActivityId();
        getUnlockReward = reqMsg.getGetUnlockReward();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        if(!SystemOpenMgr.systemOpen(player, eSystemId.AdActivity.getValue())){
            ret = GameErrorCode.E_SYSTEM_NO_OPEN;
            return;
        }
        ret = player.getModule(AdActivityModule.class).watchFinishReward(activityId, getUnlockReward);
    }

    @Override
    public void sendData(GamePlayer player) {
        if(0 != ret){
            AdActivityProto.WatchFinishRewardRespMsg.Builder respMsg = AdActivityProto.WatchFinishRewardRespMsg.newBuilder();
            respMsg.setRet(ret);
            player.sendPacket(Protocol.U_AD_WATCH_FINISH_REWARD, respMsg);
        }
    }
}
